package Client.Online;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

class ContactCellRenderer extends ContactCell implements ListCellRenderer {

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private static final Color HIGHLIGHT_COLOR = new Color(206, 227, 253);

    public ContactCellRenderer() {
        // TODO Auto-generated constructor stub
        setOpaque(true);

    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value,
            int index, boolean isSelected, boolean cellHasFocus) {
        ContactEntry entry = (ContactEntry) value;

        getLblClientName().setText(entry.getContactName());
        getLblContactIcon().setIcon(new ImageIcon(this.getClass().getResource("/icon.png")));
        getLblStatusText().setText(entry.getStatusText());

        if (isSelected) {
            setBackground(HIGHLIGHT_COLOR);
        } else {
            setBackground(Color.white);
            setForeground(Color.black);
        }
        if (entry.isOnline()) {
            getLblClientName().setFont(new java.awt.Font("Tahoma", Font.BOLD, 11));
            getLblClientName().setForeground(Color.RED);
            getLblStatusIcon().setIcon(new ImageIcon(this.getClass().getResource("/online.png")));
        } else {
            getLblClientName().setForeground(Color.BLACK);
            getLblClientName().setFont(new java.awt.Font("Tahoma", Font.ITALIC, 11));
            getLblStatusIcon().setIcon(new ImageIcon(this.getClass().getResource("/offline.png")));
        }
        return this;
    }
}
